package com.jsh.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jsh.api.entity.StockAddDTO;
import com.jsh.api.service.StockApiService;
import com.jsh.entity.ShopStock;
import com.jsh.mapper.ShopStockMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
//注意这里是org.apache.dubbo.config.annotation.Service;
//这里相当于服务端
@Service(timeout = 30000)
@Slf4j
public class StockApiServiceImpl implements StockApiService {
    @Autowired
    private ShopStockMapper shopStockMapper;
    @Override
    public Integer  addStockAddDTO(StockAddDTO stockAddDTO) {
        ShopStock shopStock = new ShopStock();
        shopStock.setGoodsId(stockAddDTO.getGoodsId());
        shopStock.setInventory(stockAddDTO.getAccount());
        log.info("StockAddDTO的参数为:{}",stockAddDTO.toString());
        shopStockMapper.insert(shopStock);
        Integer stockId = shopStock.getStockId();
        log.info("插入库存的id为:{}",stockId);
        return stockId;


    }

    @Override
    public Integer getAccount(Integer goodsId) {

        ShopStock shopStock=this.shopStockMapper.selectOne(Wrappers.<ShopStock>lambdaQuery().eq(ShopStock::getGoodsId,goodsId));

        Integer inventory = shopStock.getInventory();
        return inventory;
    }
}
